// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import 'babel-polyfill'//兼容性
import Vue from 'vue'
import Vuex from 'vuex'
import vuexAlong from 'vuex-along'
Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    teacherinfo: '',//登录信息
    teachername:'',//登录名称
    token:'',
    isaz:'',//状态
    dtid:'',//培训编码
    respath:'',
    httpapp:''
  },
  mutations: {
    increment (state,info) {
      state.teacherinfo=info
    },
    logname (state,info) {
      state.teachername=info
    },
    logtoken (state,info) {
      state.token=info
    },
    selects (state,info) {
      state.isaz=info
    },
    dtidinfo (state,info) {
      state.dtid=info
    },
    resdpath (state,info) {
      state.respath=info
    },
    httpsapp (state,info) {
      state.httpapp=info
    },
  },
  plugins: [vuexAlong({
    name: 'along',     
    local: false,     
    session: { list: [], isFilter: true } 
  })]
})

import App from './App'
import router from './router'

Vue.config.productionTip = false
import "babel-polyfill";

//mint-ui 导入
import MintUI from 'mint-ui'
Vue.use(MintUI)
import 'mint-ui/lib/style.css'

// 导入elementui - js
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(ElementUI)

import moment from 'moment'
Vue.filter('dateFormat', function (dataStr, pattern = "YYYY-MM-DD HH:mm:ss") {
  return moment(dataStr).format(pattern)
})
//导入AXios发送异步请求。
import axios from 'axios'
Vue.prototype.$axios = axios;
//axios.defaults.baseURL ='http://222.190.113.220:8601/api'//外网公共请求头配置
axios.defaults.baseURL = 'http://192.168.118.11:9600/api'//公共请求头配置
//axios.defaults.baseURL = 'http://192.168.0.158:9600/api'//公共请求头配置
//设置请求头
axios.defaults.timeout = 60000;  //超时响应
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'; // 配置请求头
axios.defaults.headers.put['Content-Type'] = 'application/x-www-form-urlencoded'; // 配置请求头
// axios.defaults.headers.post["Content-type"] = "application/json"
axios.interceptors.request.use(function (config) {
  if (!config.url.endsWith('/login')&&!config.url.endsWith('/applogin')) {
    config.headers['login_name'] = store.state.teachername;
    config.headers['Authorization'] = store.state.token;
  }
  return config
})
axios.interceptors.response.use(function(response) {
 if (response.data.statuscode == 401) {
    router.push('/login')
  }
  if (response.data.statuscode == 402) {
    router.push('/apperror')
  }
  if (response.data.statuscode == 404) {
    router.push('/error')
  }
  return response
})
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>',
  store:store //挂载vuex
})
